#ifndef EVENT_DISPATCHER_HPP
#define EVENT_DISPATCHER_HPP

#include <sys/select.h>

#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

#include <vector>
#include <algorithm>
#include <exception>

#include "util/ProxyException.hpp"

#include "Task.hpp"
#include "Event.hpp"

#include "pthread/Mutex.hpp"

class EventDispatcher {
	friend class Context;
public:
	void run();
	void addTask(Task * task);
	void removeTask(Task * task);
private:
	Mutex mutex;
	Event selectEvent;
	std::vector<Task *> tasks;

	std::vector<Task *> addTaskQueue;
	std::vector<Task *> removeTaskQueue;
	int getMaxFileDiscriptor();

	void doAdd();
	void doRemove();

};

#endif
